<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<title>礼品申请单</title>
		<!--js库及样式-->
		<script LANGUAGE="javascript" src="../script/common.js" type="text/javascript"></script>
		<!--动态js-->
		<script language="javascript" type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位
			var operatorName=Common.cOperator().name;
			var qt = {};	//数据表格对象
			var qtmx = {};
			var caigouid;//申请单号 
			var orderid;
			var b;//GiftOrder
		    var giftid;
		    var order;
	
			//页面加载方法
			function load(){
				Eui.showNavigation();
				setPages(["listview","detview","selectdetview","detviewmx","detviewmxxz","newinventoryorder"]);
				createTable();
			}
			function createTable(){
				var columns =[];
				columns[0]={type:"checkbox"}
				columns[6]={title:"操作",width:"14%",render:czFunc,order:false}
				/*var columns = [	
					{type:"checkbox"},		//复选框
					{title:"礼品申请单号",width:"20%"},	
					{title:"操作员姓名",width:"14%"},                        //点击进入修改		
					{title:"申请日期",width:"16%",render:function(v){return v?v.format():""}},			
					{title:"最近修改间",width:"16%",render:function(v){return v?Format.formatToMM(v):""}},
					{title:"预交货时间",width:"20%",render:function(v){return v?Format.formatToMM(v):""}},	
					{title:"操作",width:"14%",render:czFunc,order:false}
				]*/
				qt = new QueryTable("loy_plan_query_bill","searchForm","datalist",columns,{
					buttons:[
						{value:"增 加",actions:onNew},
						{value:"删 除",actions:onDelete1}
					]
				});
			}
			function mxcreateTable(){
				var columns =[];
				columns[0]={type:"checkbox"}
				columns[7]={title:"操作",width:"15%",render:czmxFunc,order:false}
				/*var columns = [
					{type:"checkbox"},		//复选框
					{title:"商品类型",width:"15%"},	
					{title:"商品子类型",width:"15%"},	                      //点击进入修改
					{title:"商品名称",width:"15%"},
					{title:"申请数量",width:"10%"},
					{title:"计量单位",width:"15%"},
					{title:"备注",width:"15%"},
					{title:"操作",width:"15%",render:czmxFunc,order:false}
				]*/
				qtmx = new QueryTable("loy_plan_query_item","","mxdatalist",columns,{showData:"true",
					buttons:[
						{value:"增 加",actions:xzFunc},
						{value:"删 除",actions:onDelete},
						{value:"返 回",actions:resetFunc}
					]
				});
				qtmx.paramFunc = function(){
					var params = {};
					params.giftOrder = orderid;
					return params;
				}
			}
			function showData(){
				qt.showTable();
			}
			function czmxFunc(v,r){
				return "<a href=# onclick=\"xiugai("+r[0]+",'"+r[3]+"','"+r[4]+"','"+r[5]+"','"+r[6]+"');return false;\">修改</a>"
			}
			function czFunc(v,r){
			    return "<a href=# onclick=\"create("+r[0]+",'"+r[1]+"','"+r[2]+"','"+r[3]+"','"+r[4]+"');return false;\">操作</a>"
			}
			//进入明细页面    
		    function xiugai(id,giftName,reqQty,baseUOM,comments){
				if (id != null){
				    $("caigoumx").id.value=id;
				    $("giftName").innerHTML=giftName;
				    $("caigoumx").reqQty.value=reqQty;
				    $("baseUOM").innerHTML=baseUOM;
				    if(comments=="null"){
				    	comments="";
				    }
				    $("caigoumx").comments.value=comments;
					switchPage("detviewmx");
				}
			}
			
			function create(id,codeid,opera,update,over){
				orderid=id;

			 	if (id != null){
				 	$("caigouid").innerHTML=codeid;
				 	$("zdtime").innerHTML=update;
				 	$("oper").innerHTML=opera;
		      
		            	$("updatetime").innerHTML=over;
		   
				 	mxcreateTable();
					switchPage("selectdetview");
				}
			}
			function onUpdateOrder(){
				if(!checkForm("inventoryorder"))return;
				var date1=$("inventoryorder").reqDeliDate2.value;
			    DWR.call('giftStorageService.updateGiftOrder',orderid,date1,function(v){
			    	$("updatetime").innerHTML=v.reqDeliDate.format();
                    switchPage("detview");
			    });  
			}
			function onNew(){
			    DWR.call('giftStorageService.createGiftOrder',1,function(v){
				    getOrderId(v.id);
				    $("caigouid2").innerHTML=v.orderCode;
				 	$("zdtime2").innerHTML=v.reqDateTime.format();
				 	$("oper2").innerHTML=operatorName;
				    orderid=v.id;
				    switchPage("newinventoryorder");
			    });
			}
			function getOrderId(d){
				b=d;
			}
			//选择单位控件
			function selOrg(){	
				var v = openDialogFrame("/client/giftrule_list.html",'选择商品',500,600)
				if (v){		
	            	$("white_enterform").awardname.value = v.name;
				    giftid=v.id;
				}
			}
			function selOrg2(){			
				var v = openDialogFrame("/client/giftrule_list.html",'选择商品',500,600)
				if (v){		
	            	$("caigoumxxz").giftName.value = v.name;
				    giftid=v.id;
				}
			}
			//取消方法
			function resetFunc(){
				switchPage('listview');
				showData();
			}
			//保存方法
			function onSave(){
				if(!checkForm(white_enterform))return;
		       	var white_enter = Common.getValues(white_enterform);
			    if (!white_enter.id)
		    	white_enter.giftOrder=b;
		        white_enter.gift=giftid;
			 	DWR.call('giftStorageService.addGiftItem',white_enter,Constants.GIFT_ORDER_TYPE_PLAN,function(v){
	           		if(v==1){
	            		     showError("添加失败，已有此商品了");
	           		}else{
	           			showInformation("添加成功!");
	           		}
	   			},{blockScreen:"true"});
		    	white_enterform.reset();	  
			}  
			function mxxzonSavexg(){
			   if(!checkForm("caigoumxxz"))return;
		   	   var giftItem = Common.getValues("caigoumxxz");
			   if (!giftItem.id)
			   	   giftItem.giftOrder=orderid;
			       giftItem.gift=giftid;
			   DWR.call('giftStorageService.addGiftItem',giftItem,Constants.GIFT_ORDER_TYPE_PLAN,function(v){
		           if(v==1){
		           	   showError("添加失败，已有此商品了");
		           }
		           else{
		           	   showInformation("添加成功!");
		           }
		       	},{blockScreen:"true"});
		       	$("caigoumxxz").reset();        
			}
			function onSavexg(){
			    if(!checkForm("caigoumx"))return;
			    var giftItem=Common.getValues("caigoumx");
				DWR.call('giftStorageService.updateGiftItem',giftItem,Constants.GIFT_ORDER_TYPE_PLAN,function(v){
			    	if(v==1){
			       	    showInformation("修改成功!");
			        }
					switchPage('selectdetview');	
			    	mxcreateTable();
			    },{blockScreen:"true"});	
			}
			function qx(){
				switchPage('selectdetview');
				mxcreateTable();
			}
			function xzFunc(){
				$("caigoumxxz").reset();
				switchPage('detviewmxxz');
			}
			function resetItem(){
		    	white_enterform.reset();
			}
			function resetItem2(){
		    	$("caigoumxxz").reset();
			}
			//删除方法
			function onDelete(){
				//var	id = Common.getCheckBoxValue("checkboxs");
				var	id = qtmx.getBoxValue();
				if(id==null||id==""){
					showWarning("请选择您确定要删除的数据");return;
				}
				if(showQuestion("确定删除吗?")==false){
					return;
				}  	 
				var ids = id.split(",");
				DWR.call('giftStorageService.deleteGiftItemByIds',ids,function(v){
			    	mxcreateTable();
			        showInformation("删除成功!");
			        switchPage('selectdetview');
				},{blockScreen:"true"});		
			}
			function onDelete1(){
				var	id = qt.getBoxValue();
				if(id==null||id==""){
					showWarning("请选择您确定要删除的数据");return;
				}
				if(showQuestion("确定删除吗?")==false){
					return;
				}  	 
				var ids = id.split(",");		
				DWR.call('giftStorageService.deleteGiftOrderByIds',ids,function(v){
			    	showData();
			        showInformation("删除成功!");
			    },{blockScreen:"true"});
				switchPage('listview');
			}
			function blakItemList(){
				DWR.call('giftStorageService.getOrder',b,function(v){
				    $("caigouid").innerHTML=v.orderCode;
				 	$("zdtime").innerHTML=v.reqDateTime.format();
				 	$("oper").innerHTML=v.operator;        
			    },{blockScreen:"true"});
			    orderid=b;
			    mxcreateTable();
				switchPage('selectdetview');	    
			}
			function onCanc(){
				switchPage('listview');
			}	
			function backdeleteOrder(){
			DWR.call('giftStorageService.deleteGiftOrderById',b,function(v){
			     switchPage('listview');
			    },{blockScreen:"true"});
			  
			}	
		</script>
	</HEAD>
	<body onload="load()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<!--查询静态页面部分-->
		<div id="listview" style="">
			<div class="searchForm">
				<form id="searchForm" name="searchForm">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
						<tr>  
					    	<td><label>申请单号</label> <input type="text" name="orderCode" maxlength=15></td>
							<td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员</label> <input type="text" name="operator" maxlength=20></td>
						</tr>
						<tr>
						    <td><label>申请日期</label> <input type=text name="reqDateTime" onblur="checkV(this,'date')"><a href="javascript:void(0)" onclick='showDatePicker( $("reqDateTime"));' class="date" title="选择日期">&nbsp;&nbsp;</a></td>
						    <td><label>预交货日期</label> <input type=text name="reqDeliDate" onblur="checkV(this,'date')"><a href="javascript:void(0)" onclick='showDatePicker( $("reqDeliDate"));' class="date" title="选择日期">&nbsp;&nbsp;</a></td>
							<td><button type="button" onclick="showData()">查 询</button></td>
						</tr>
					</table>
				</form>
			</div>
			<div id="datalist"></div>
		</div>
		<div id="selectdetview" style="display:none;">
			<div class="form">
				<form id="selectdetform" name="selectdetform">
					<div class="formTitle">商品信息列表</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
						<tr>
							<td><label>申请单号</label> <span id="caigouid"></span></td>
							<td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员</label> <span id="oper"></span></td>
						</tr>
						<tr>
							<td><label>申请日期</label> <span id="zdtime"></span></td>
							<td><label>预交货日期</label> <span id="updatetime"></span></td>
						</tr>
					</table>
					<input type="hidden" name="count" onblur="checkV(this,'',true)">
				</form>
			</div>
			<div id="mxdatalist"></div>
		</div>
		<!--明细(新增)静态页面部分-->
		<div id="detview" style="display:none;">
			<form id="white_enterform" name="white_enterform">
				<input type="hidden" name="gift">
				<div class="form">
					<div class="formTitle">商品详细信息</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品名称</label> <input type="text" name="awardname" onblur="checkV(this,'',true)" readonly class="readonly"><a class=orga href=# onclick="selOrg()">&nbsp;&nbsp;</a><font class="des">*</font></td> 
							<td><label>申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)" maxlength=15><font class="des">*</font></td>
						</tr>
						<tr>		
							
							<td><label>备&nbsp;&nbsp;&nbsp;&nbsp;注</label> <input type="text" name="comments"  maxlength="80"></td>
						</tr>		
					</table>
				</div>
				<div align="center"><button type="button" onclick="onSave()">添 加</button> <button type="button" onclick="resetItem()">清 除</button> <button type="button" onclick="onCanc()">取 消</button> <button type="button" onclick="blakItemList()">返 回</button></div>
			</form>
		</div>
		<div id="detviewmx" style="display:none;">
			<div class="form">
				<form id="caigoumx" name="caigoumx">					
					<input type="hidden" name="id">
					<div class="formTitle">修改礼品申请项</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
						<tr>
							<td><label>商品名称</label> <span id="giftName"></span></td>
							<td><label>申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)" maxlength=15><font class="des">*</font></td>
						</tr>
						<tr>		
							<td><label>计量单位</label> <span id="baseUOM"/></td>
							<td><label>备&nbsp;&nbsp;注:&nbsp;</label> <input type="text" name="comments"  maxlength="80"></td>
						</tr>			
					</table>		
					<div align="center"><button type="button" onclick="onSavexg()">修 改</button> <button type="button" onclick="qx()">取 消</button></div>
				</form>
			</div>
		</div>
		<div id="detviewmxxz" style="display:none;">
			<form id="caigoumxxz" name="caigoumxxz">
				<input type="hidden" name="id">
				<div class="form">
					<div class="formTitle">添加礼品申请项</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品名称</label> <input type="text" name="giftName" onblur="checkV(this,'',true)" readonly class="readonly"><a class=orga href=# onclick="selOrg2()">&nbsp;&nbsp;</a><font class="des">*</font></td>  
							<td><label>申请数量</label> <input type="text" name="reqQty" onblur="checkV(this,'number',true)" maxlength=8><font class="des">*</font></td>
						</tr>	
					</table>
				</div>
				<div align="center"><button type="button" onclick="mxxzonSavexg()">确 定</button> <button type="button" onclick="resetItem2()">清 除</button> <button type="button" onclick="qx()">返 回</button></div>
			</form>
		</div>
		<div id="newinventoryorder" style="display:none;">
			<div class="form">
				<form id="inventoryorder" name="inventoryorder">
					<input type="hidden" name="neworderid">
					<div class="formTitle">填写礼品申请单据</div>
					<br>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
						<tr>
							<td><label>申请单号</label> <span id="caigouid2"></span></td>
							<td><label>操&nbsp;&nbsp;作&nbsp;&nbsp;员</label> <span id="oper2"></span></td>
						</tr>
						<tr>
							<td><label>申请日期</label> <span id="zdtime2"></span></td>
							<td><label>预交货日期</label> <input type=text name="reqDeliDate2" onblur="checkV(this,'_futureDate',true)"><a href="javascript:void(0)" onclick='showDatePicker( $("reqDeliDate2"));' class="date" title="选择日期">&nbsp;&nbsp;</a><font class="des">*</font></td>
						</tr>
					</table>
					<br>
					<br>
					<div align="center"><button type="button" onclick="onUpdateOrder()">添加礼品项</button> <button type="button" onclick="backdeleteOrder()">取消单据</button></div>
				</form>
			</div>	
		</div>
	</body>
</HTML>